/**
 * 数据统计管理初始化
 */
var Achievements = {
    id: "AchievementsTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
Achievements.initColumn = function () {
    return [
        {field: 'selectItem', radio: true},
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle', hidden: true},
        {title: '排名', field: 'rank', align: 'center', valign: 'middle',},
        {title: '人员', field: 'name', align: 'center', valign: 'middle',},
        // {title: '考试名称', field: 'theTestName', align: 'center', valign: 'middle',},
        // {title: '试卷总分', field: 'totalScore', align: 'center', valign: 'middle',},
        // {title: '通过分数：', field: 'scoresOfAdoption', align: 'center', valign: 'middle',},
        // {
        //     title: '是否通过：',
        //     field: 'isAdoption',
        //     align: 'center',
        //     valign: 'middle',
        //     formatter: function (value, row, index) {
        //         if (value == 1) {
        //             return "通过";
        //         } else {
        //             return "未通过";
        //         }
        //     }
        // },
        {title: '考试成绩', field: 'theTestScore', align: 'center', valign: 'middle',},
        // {title: '交卷时间', field: 'submitTime', align: 'center', valign: 'middle',},
        // {title: '备注：', field: 'remark', align: 'center', valign: 'middle'},
    ];
};


/**
 * 检查是否选中
 */
Achievements.check = function () {
    var selected = $('#' + this.id).bootstrapTable('getSelections');
    if (selected.length == 0) {
        Feng.info("请先选中表格中的某一记录！");
        return false;
    } else {
        Achievements.seItem = selected[0];
        return true;
    }
};
/**
 * 点击添加考试
 */
Achievements.addRemark = function () {
    if (this.check()) {
        var index = layer.open({
            type: 2,
            title: '',
            area: ['800px', '420px'], //宽高
            fix: false, //不固定
            maxmin: true,
            content: Feng.ctxPath + '/achievements/addAchievementsRemark/' + Achievements.seItem.id
        });
        this.layerIndex = index;
    }
};

/**
 * 查询表单提交参数对象
 * @returns {{}}
 */
Achievements.formParams = function () {
    var queryData = {};
    queryData['theTestName'] = $("#theTestName").val();
    queryData['userName'] = $("#userName").val();
    queryData['startTime'] = $("#startTime").val();
    queryData['endTime'] = $("#endTime").val();
    return queryData;
}

/**
 * 查询考试列表
 */
Achievements.search = function () {
    Achievements.table.refresh({query: Achievements.formParams()});
};

Achievements.resetSearch = function () {
    $("#theTestName").val("");
    $("#userName").val("");
    $("#startTime").val("");
    $("#endTime").val("");
    Achievements.search();
};

var parseParam = function (param, key) {
    var paramStr = "";
    if (param instanceof String || param instanceof Number || param instanceof Boolean) {
        paramStr += "&" + key + "=" + param;
    } else {
        $.each(param, function (i) {
            var k = key == null ? i : key + (param instanceof Array ? "[" + i + "]" : "." + i);
            paramStr += '&' + parseParam(this, k);
        });
    }
    return paramStr.substr(1);
};


$(function () {
    $(function () {
        var defaultColunms = Achievements.initColumn();
        var table = new BSTable(Achievements.id, "/achievements/list", defaultColunms);
        table.setPaginationType("server");
        table.setQueryParams(Achievements.formParams());
        Achievements.table = table.init();
    });

});
